﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SMTC.BO.Common
{
    public class DbValueProccess
    {
        /// <summary>
        /// 处理字符串，默认为like处理方式
        /// </summary>
        /// <param name="Str"></param>
        /// <param name="isLike"></param>
        /// <returns></returns>
        public static string StrProccess(string Str, bool isLike = true)
        {
            if (isLike == false)
            {
                if (string.IsNullOrEmpty(Str))
                {
                    return "";
                }
                else
                {
                    if (string.IsNullOrEmpty(Str.Trim()))
                    {
                        return "";
                    }
                    else
                    {
                        return Str.Trim();
                    }
                }
            }
            else
            {
                if (string.IsNullOrEmpty(Str))
                {
                    return "%%";
                }
                else
                {
                    if (string.IsNullOrEmpty(Str.Trim()))
                    {
                        return "%%";
                    }
                    else
                    {
                        return "%" + Str.Trim() + "%";
                    }
                }
            }
        }
        /// <summary>
        /// 处理时间，默认为最小处理
        /// </summary>
        /// <param name="dateTime"></param>
        /// <param name="isMin"></param>
        /// <returns></returns>
        public static DateTime DateTimeProccess(DateTime? dateTime, bool isMin = true)
        {
            if (isMin == true)
            {
                if (dateTime == null || dateTime.Value < new DateTime(1900, 1, 1) || dateTime.Value > new DateTime(2999, 12, 31))
                {
                    return new DateTime(1900, 1, 1);
                }
                else
                {
                    return dateTime.Value;
                }
            }
            else
            {
                if (dateTime == null || dateTime.Value < new DateTime(1900, 1, 1) || dateTime.Value > new DateTime(2999, 12, 31))
                {
                    return new DateTime(2999, 12, 31);
                }
                else
                {
                    return dateTime.Value;
                }
            }
        }
        /// <summary>
        /// 处理整形数据
        /// </summary>
        /// <param name="objecti"></param>
        /// <returns></returns>
        public static int IntProccess(int objecti)
        {
            if (objecti == null)
            {
                return 0;
            }
            else
            {
                return objecti;
            }
        }
    }
}
